package com.example.ordersystem.service;

import com.example.ordersystem.mapper.GoodMapper;
import com.example.ordersystem.model.Goods;
import com.example.ordersystem.model.PageRequest;
import com.example.ordersystem.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: GoodService
 * @author: 芃
 * @description: 商品服务类
 * @date: 2024/12/31 15:26
 */
@Service
public class GoodService {

    @Autowired
    private GoodMapper goodMapper;

    public Integer addGood(String goodName,Double goodPrice,Integer goodNum) {
        Goods goods = new Goods();
        goods.setGoodName(goodName);
        goods.setGoodPrice(goodPrice);
        goods.setGoodNum(goodNum);
        goodMapper.addGood(goods);
        return goods.getId();
    }

    public PageResult<Goods> getListByPage(PageRequest pageRequest) {
        Integer count = goodMapper.count();
        List<Goods> GoodsList = goodMapper.queryListBypage(pageRequest);
        return new PageResult<>(GoodsList,count,pageRequest);
    }



    public Boolean deleteByGoodId(Integer id) {
        Integer result = goodMapper.deleteByGoodId(id);
        if (result == 1){
            return true;
        }else{
            return false;
        }
    }



}
